package com.example.qjia.ui.activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.example.qjia.Presenters.LoginPresenter;
import com.example.qjia.Presenters.LoginPresenterImp;
import com.example.qjia.R;
import com.example.qjia.basic.BaseActivity;
import com.example.qjia.ui.ViewInterface.LoginViewInterface;

public class LoginActivity extends BaseActivity implements LoginViewInterface, View.OnClickListener {

    private EditText username;
    private EditText password;
    private Button loginBt;
    private ProgressBar progressBar;
    private LoginPresenter mloginPresenter;
    private TextView newUser;
    @Override
    protected int getLayoutResourceId() {
        return R.layout.activity_login;
    }

    @Override
    protected void init() {

        username=(EditText)findViewById(R.id.account);
        password=(EditText)findViewById(R.id.password);
        loginBt=(Button)findViewById(R.id.btn_login);
        newUser=(TextView)findViewById(R.id.new_user);
        loginBt.setOnClickListener(this);
        progressBar=(ProgressBar)findViewById(R.id.progress);
        newUser.setOnClickListener(this);
        mloginPresenter=new LoginPresenterImp(this);


    }

    @Override
    protected void initView() {

    }

    @Override
    public void showProgress() {

        progressBar.setVisibility(View.VISIBLE);
    }

    @Override
    public void hideProgress() {

        progressBar.setVisibility(View.INVISIBLE);
    }

    @Override
    public void showFail(String msg) {    //提示登录失败的信息

        toast(msg);

    }

    @Override
    public void toNext() {                 //登录成功就会跳转
        Intent intent =new Intent(LoginActivity.this,MainActivity.class);
        startActivity(intent);
    }

    @Override
    public void onClick(View view) {
        if(view.getId()==R.id.btn_login)
        mloginPresenter.onLogin(username.getText().toString(),password.getText().toString());
        if (view.getId()==R.id.new_user)startActivity(new Intent(LoginActivity.this,RegisterActivity.class));
    }
}
